package com.joker.mapper;

import com.joker.entity.Chat;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * <p>
 * 聊天记录表 Mapper 接口
 * </p>
 *
 * @author joker
 * @since 2021-06-03
 */
@Component
public interface ChatMapper extends BaseMapper<Chat> {
    @Select("select * from chat where (chat_send = #{userId} and chat_receive = #{toUserId}) or" +
            " (chat_send = #{toUserId} and chat_receive = #{userId}) order by chat_date")
    public List<Chat> findAllToUserOrToUser(String userId, String toUserId);
    @Update("UPDATE chat SET read_flag = 1" +
            " WHERE chat_send = #{toUserId} and chat_receive = #{userId} and read_flag = 0")
    public void setReadFlagByUserIdAndToUserId(String userId, String toUserId);
}
